/**
 * WeeShop 声明
 * ===========================================================
 * 网站： https://www.darlang.com
 * 标题： ECShop 小程序「weeshop 」- 基于 ECShop 为后台系统开发的非官方微信商城小程序
 * 链接： https://www.darlang.com/?p=709
 * 说明： 源码已开源并遵循 Apache 2.0 协议，你有权利进行任何修改，但请保留出处，请不要删除该注释。
 * ==========================================================
 * Copyright 2019 darlang
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ===========================================================
 */

// list.js
import {PNT,setNavBarTitle,formatTime,scrollLoadList} from '../../../../utils/utils';
import {GetWaitComment} from '../../../../utils/apis';

Page({
  /**
   * 页面的初始数据
   */
  data: {
    commentState: 0,
    goodsId: null,
    commentLst: '',
    pages: {
      page: 1,
      size: 10,
      total: 10,
      done: false,
      loading: false
    },
    page:0,
    list:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (opt) {
    setNavBarTitle(PNT.comments.list);
    var info = wx.getStorageSync("userInfo");
    this.setData({
      goodsId: opt.goodsId,
      info:info,
    });
    this.getCommentLst();
  },

  comment:function(e){
      var id = e.currentTarget.dataset.id;
      if(!id){
        wx.showToast({
          title: '系统繁忙,请稍后再试',
          icon:'none',
        })
        return;
      }
      wx.navigateTo({
        url: '/pages/member/comment/add/add?id='+id,
      })
  },

  /**
   * 评论列表
   * @author darlang
   */
  getCommentLst() {
    var that = this;
    if (this.data.pages.done) {
      return false;
    }
    wx.showLoading({title: '加载中...',mask: true});
    GetWaitComment(this.data.info.user_id,this.data.page).then(res => {
      console.log(res);
      var list = that.data.list;
      if(res.data.length >0){
        for(var i = 0;i<res.data.length;i++){
          list.push(res.data[i]);
        }
      }
      that.setData({
        list:list,
      })
      return;
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.changeCommentState();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    // var page
    // this.getCommentLst();
  },
});